﻿Public Class InserLogClass
    Implements IDisposable
    Dim cn As DCM_SQL_Sqlite.C_SQL
    Private Const DBFileName_相对路径 As String = "日志\DCMHttpServerLog.db"
    Private DBFileName_绝对路径 As String = ""
    Private DBPath As String = ""
    Private Const TBName As String = "Log"
    Private Shared elEvents As EventLog
    Public Sub New()
        Dim FNS = DCM.DCM_IO.Get_FileInfoFromFileName(Windows.Forms.Application.ExecutablePath)
        DBFileName_绝对路径 = FNS.路径 & "\" & DBFileName_相对路径
        DBPath = "Data Source=" & DBFileName_绝对路径 & ";Version=3;"
        cn = New DCM_SQL_Sqlite.C_SQL(DBPath)
        elEvents = New EventLog
        elEvents.Source = "信息公示平台日志记录器"
        elEvents.WriteEntry("启动日志记录器")
        InsertLog(0, "启动日志记录器", "系统")
    End Sub
    Public Sub InsertLog(UserID As IntPtr, 内容 As String, UserName As String)
        InsertLog(CInt(UserID), 内容, UserName)
    End Sub
    Public Sub InsertLog(UserID As Integer, 内容 As String, UserName As String)
        Try
            If UserName = "" Then UserName = "系统"
            cn.Insert(TBName, {"时间", "内容", "UserID", "UserName"}, {Now, 内容, UserID, UserName})
        Catch ex As Exception
            elEvents.WriteEntry(ex.Message)
        End Try
    End Sub

#Region "IDisposable Support"
    Private disposedValue As Boolean ' 要检测冗余调用

    ' IDisposable
    Protected Overridable Sub Dispose(disposing As Boolean)
        If Not disposedValue Then
            If disposing Then
                ' TODO: 释放托管状态(托管对象)。
                Try
                    cn.Dispose()
                Catch ex As Exception

                End Try
            End If

            ' TODO: 释放未托管资源(未托管对象)并在以下内容中替代 Finalize()。
            ' TODO: 将大型字段设置为 null。
        End If
        disposedValue = True
    End Sub

    ' Visual Basic 添加此代码以正确实现可释放模式。
    Public Sub Dispose() Implements IDisposable.Dispose
        ' 请勿更改此代码。将清理代码放入以上 Dispose(disposing As Boolean)中。
        Dispose(True)
        ' TODO: 如果在以上内容中替代了 Finalize()，则取消注释以下行。
        ' GC.SuppressFinalize(Me)
    End Sub
#End Region



End Class


